home *** CD-ROM | disk | FTP | other *** search
- Path: news.clark.net!not-for-mail
- From: gusty@clark.net (Harlan Messinger)
- Newsgroups: comp.lang.c++
- Subject: Re: Will it be auto-deleted?
- Date: 21 Feb 1996 23:14:59 GMT
- Organization: Clark Internet Services, Inc., Ellicott City, MD USA
- Message-ID: <4gg91j$gdc@clarknet.clark.net>
- References: <1996Feb20.110314.46035@yogi.urz.unibas.ch>
- NNTP-Posting-Host: explorer.clark.net
- Mime-Version: 1.0
- Content-Type: TEXT/PLAIN; charset=ISO-8859-1
- Content-Transfer-Encoding: 8bit
- X-Newsreader: TIN [UNIX 1.3 950726BETA PL0]
-
- Song Jin (song@iso.iso.unibas.ch) wrote:
- : I have a question:
- :
- : void myfunction(void)
- : {
- : double *mypointer = new double[100];
- :
- : .....
- :
- : }
- :
- : The mypointer and the buffer it pointed will be auto-deleted after returned
- : from myfunction, am I right?
- :
-
- Absolutely not. Any memory allocated with new has to be deleted
- explicitly.
-
- delete [] mypointer;
-
- Otherwise, once all pointers to it have gone out of scope, it'll just sit
- there unreachable until the heap itself is returned to wherever it came
- from (if that happens) or garbage collection returns it to the heap (if
- your system has garbage collection) or until the machine is rebooted. This
- is called a "memory leak".
-
-